import * as api from './util';

export function sendVCode(code) {
  return api.post('/app/OAuth/getSessionKey', {
    code
  });
}

export function login(postbody) {
  return api.post('/app/OAuth/getUserMobile', postbody);
}

export function getUserInfo() {
  return api.get('/auth/info');
};

export function loginByPwd(phone, password) {
  let postbody = {
    phone: phone,
    loginType: 'APPLETS_PROVIDER'
  }
  return api.post('/applets/provider/customUser/experienceLogin', postbody);
}

export function loginByToken(token, curShardingId) {
  let postbody = {
    token: token,
    curShardingId: curShardingId,
    appId: 'wx372c6e1f8494d635',
    loginType: 'APPLETS_PROVIDER'
  }
  return api.get('/applets/loginByToken', postbody);
}

export function logout(token) {
  return api.post('/applets/customUser/logout', {
    token
  });
}

export function updateSwitchInfo() {
  return api.get('/applets/provider/customUser/info');
}

/**
 * 找回密码点击下一步
 * @param {*} phone 
 * @param {*} vCode 
 */
export function findPasswordNextStep(phone, vCode) {
  let postBody = {
    phone: phone,
    phoneVCode: vCode
  };
  return api.post('/applets/buyer/pwdNextStep', postBody)
}

/**
 * 找回密码:设置新密码
 * @param {*} password 
 * @param {*} authorizationCode 
 */
export function findPassword(password, authorizationCode) {
  let postbody = {
    password: password,
    authorizationCode: authorizationCode
  };
  return api.post('/applets/buyer/findPassword', postbody);
}

/**
 * 修改密码
 * @param {*} phone 
 * @param {*} password 
 */
export function setPassword(phone, password) {
  let postbody = {
    phone: phone,
    confirmNewPwd: password,
    newPwd: password
  };
  return api.post('/applets/customUser/newPassword', postbody);
}
// 随机体验账号
export function RandomAccount(postbody) {
  return api.post('/applets/provider/customUser/experiencePhone', postbody)
}
// 自动登录
export function re_login(postbody) {
  return api.post('/applets/provider/customUser/experienceLogin', postbody)
}